package cn.lvhang.user.controller;

import cn.lvhang.basic.exception.BusinessException;
import cn.lvhang.basic.util.AjaxResult;
import cn.lvhang.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * 前端传的参数很少
     * 一定情况下，map可以对象接收参数
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody Map<String,String> param){
        try {
            //register:用户注册  binder:用户绑定
            iVerifyCodeService.smsCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙，稍后重试！！");
        }

    }

}
